import java.math.BigDecimal;
import java.util.List;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

/**
 * @author understand
 * @description:
 * @create 2025/5/24 0:38
 */
public class FunctionAPI {
    public static void main(String[] args) {

        List<String> list = List.of("1", "2", "3", "4", "5");
        Function<String, BigDecimal> stringIntegerFunction =  s -> BigDecimal.valueOf(Optional.of(Integer.parseInt(Optional.ofNullable(s).orElse("0"))).get());
        BigDecimal value = list.stream().map(stringIntegerFunction).reduce(BigDecimal.ZERO, BigDecimal::add);
        System.out.println(value);

    }
    public static <T> void eval(List<T> list, Predicate<T> predicate) {
        for (T t : list) {
            if (predicate.test(t)) {
                System.out.println(t);
            }
        }
    }

    /**
     * 1.使用回调函数的时候泛型类已经确定，所以不用再指定泛型类
     * 2.<VO extends Car 可以使用公共父类的属性---vo.setName("sd");
     * 3.定义了一个函数式接口变量Function<String, BigDecimal> stringIntegerFunction =s -> BigDecimal.valueOf(Optional.of(Integer.parseInt(Optional.ofNullable(s).orElse("0"))).get());
     * @param supplier
     * @param <VO>
     * @param <DO>
     * @return
     */
    public static <VO extends Car, DO> VO ConvertTO(
            DO do1,
            Supplier<VO> supplier,
            BiConsumer<DO,VO> callBack) {
        VO vo = supplier.get();
        vo.setName("sd");
//        BeanUtils.copyProperties(do,vo);
        callBack.accept(do1,vo);
        return vo;
    }
    /**
     * Function
     */
}
